﻿#include "widget.h"
#include <QPushButton>
#include <iostream>
#include "time.h"


using namespace std;


Widget::Widget(QWidget *parent)
    : QWidget(parent)
{
    //设置窗体属性
    setWindowTitle("myfirst qt");
    this->resize(500,500);

    //设置按钮
    //第一个按钮
    QPushButton *btn_01 = new QPushButton;
    btn_01->setText("给你一哈");
    btn_01->setParent(this);
    btn_01->move(400,200);
    //第二个按钮
    QPushButton *btn_02 = new QPushButton("给你两哈",this);
    btn_02->move(80,80);

    QPushButton *btn_03 = new QPushButton("槽函数测试",this);
    // 实现系统自带信号和自定义槽函数的连接
    connect(btn_03, &QPushButton::clicked, this,&Widget::MoveButton);
}

Widget::~Widget()
{

}

void Widget::MoveButton()
{
    static int i = 0;
    srand(i);
    int num = rand();
    i+=num;

    btn_03->move(i%200, i%200);
}
